from typing import Optional
from pywinauto import Application, WindowSpecification
from automaticAI.src.utils.logger import logger


class WindowsController:
    """
    windows操作类api封装
    """

    def __init__(self) -> None:
        """
        初始化 Windows 控制器。
        """
        self.app: Optional[Application] = None
        self.window: Optional[WindowSpecification] = None

    def open_app(self, app_path: str) -> bool:
        """
        打开指定的应用程序。
        :param app_path: 应用程序的路径
        :return: 是否成功打开
        """
        try:
            self.app = Application(backend="uia").start(app_path)
            logger.info(f"成功打开应用程序: {app_path}")
            return True
        except Exception as e:
            logger.error(f"打开应用程序失败,请检查应用路径: {e}")
            return False


if __name__ == '__main__':
    app_path = r"D:\bao\QQ.exe"
    WindowsController().open_app(app_path)
